home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / VideoToolbox 94.11.17 / Demos / Quitter.c < prev    next >
Encoding:
Text File  |  1994-09-10  |  2.5 KB  |  54 lines  |  [TEXT/KAHL]

  1. oolbox
  2. application that accepts AppleEvents commanding it to produce visual stimuli. 
  3.  
  4. HISTORY:
  5. 3/5/93 dgp wrote it
  6. 3/9/93    dgp got it to work, by setting the HighLevelEvent-Aware bit, as instructed
  7. by Larry Harris, 76150,1027, a friendly fellow programmer on CompuServe.
  8. 4/17/93    dgp    #include VideoToolbox.h for PrintfExit().
  9. 12/15/93 dgp Go away quietly if user hits Cancel.
  10. 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
  11.             Metrowerks CodeWarrior C.
  12. 9/5/94 dgp removed assumption in printf's that int==short.
  13. */
  14. #include "VideoToolbox.h"
  15. #include <stdarg.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <AppleEvents.h>
  19.  
  20. void main(void)
  21. {
  22.     int error;
  23.     unsigned char prompt[]="\pChoose a program to quit.";
  24.     PortInfoRec portInfo;
  25.     TargetID targetID;
  26.     AEAddressDesc target;
  27.     AppleEvent appleEvent,reply;
  28.     AESendMode sendMode;
  29.     long value;
  30.  
  31.     printf("Welcome to Quitter.\n");
  32.     Gestalt(gestaltAppleEventsAttr,&value);
  33.     if(!(value&(1<<gestaltAppleEventsPresent)))PrintfExit("Sorry, I need AppleEvents.\n");
  34.     PPCInit();
  35.     // Select target through dialog with user.
  36.     error=PPCBrowser(prompt,NULL,0,&targetID.location,&portInfo,NULL,NULL);
  37.     if(error==-128)abort();    // User pressed Cancel.
  38.     if(error)PrintfExit("PPCBrowser error %d\n",error);
  39.     targetID.name=portInfo.name;
  40.     error=AECreateDesc(typeTargetID,(Ptr)&targetID,sizeof(targetID),&target);
  41.     if(error)PrintfExit("AECreateDesc error %d\n",error);
  42.     error=AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&target
  43.         ,kAutoGenerateReturnID,kAnyTransactionID,&appleEvent);
  44.     if(error)PrintfExit("AECreateAppleEvent error %d\n",error);
  45.     error=AEDisposeDesc(&target);
  46.     sendMode=kAENoReply+kAENeverInteract+kAEDontReconnect;
  47.     error=AESend(&appleEvent,&reply,sendMode,kAENormalPriority
  48.         ,kAEDefaultTimeout,NULL,NULL);
  49.     if(error)PrintfExit("AESend error %d\n",error);
  50.     error=AEDisposeDesc(&appleEvent);
  51.     if(error)PrintfExit("AEDisposeDesc error %d\n",error);
  52.     printf("Done. “%s” has been asked to quit.\n",p2cstr(targetID.name.name));
  53. }
  54.